using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;
namespace Microsoft.Expression.Interactivity.Core
{
	public class RemoveElementAction : TargetedTriggerAction<FrameworkElement>
	{
		protected override void Invoke(object parameter)
		{
			if (base.AssociatedObject != null && base.Target != null)
			{
				DependencyObject parent = base.Target.get_Parent();
				Panel panel = parent as Panel;
				if (panel != null)
				{
					panel.get_Children().Remove(base.Target);
					return;
				}
				ContentControl contentControl = parent as ContentControl;
				if (contentControl != null)
				{
					if (contentControl.get_Content() == base.Target)
					{
						contentControl.set_Content(null);
					}
					return;
				}
				ItemsControl itemsControl = parent as ItemsControl;
				if (itemsControl != null)
				{
					itemsControl.get_Items().Remove(base.Target);
					return;
				}
				if (parent != null)
				{
					throw new InvalidOperationException(ExceptionStringTable.UnsupportedRemoveTargetExceptionMessage);
				}
			}
		}
	}
}
